package org.onionframework.faces.extension;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

@Component
public class BeanNamespacePostProcesser implements BeanFactoryPostProcessor {

	@Override
	public void postProcessBeanFactory(
			ConfigurableListableBeanFactory beanFactory) throws BeansException {
		String[] beanNames = beanFactory.getBeanDefinitionNames();
		for(String beanName : beanNames){
			if(beanName.indexOf('.') == -1)
				continue;
			else{
				String[] terms = beanName.split("\\.");
				Namespace space = Namespace.rootNamespace;
				for(int i = 0;i<terms.length - 1; i++){
					space = space.getOrCreateChild(terms[i]);
				}
			}	
		}
	}

}
